/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sokobantest;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;

/**
 *
 * @author bram
 */
public class Board extends JPanel {
    
    private int w = 0;
    private int h = 0;
    private int x = 0;
    private int y = 0;
    private int space = 48;
    private String level = 
              "    ######          \n"
            + "    ##   #         x\n"
            + "    ##$  #         x\n"
            + "  ####  $##         \n"
            + "  ##  $ $ #         \n"
            + "#### # ## #   ######\n"
            + "##   # ## #####  ..#\n"
            + "## $  $          ..#\n"
            + "###### ### #@##  ..#\n"
            + "    ##     #########\n"
            + "    ########        ";
    
    public Board(){
        addKeyListener(new TAdapter());
        setFocusable(true);
        setPreferredSize(new Dimension(1024,720));
        setBackground(Color.green);
    }
    
    public void buildWorld(Graphics g) {
        GameObject test = new GameObject();
        Image[][] world = new Image[11][20];
        world = test.defineWorld(level);
        
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        g.setColor(new Color(250, 240, 170));
        
        int calcX = 0;
        int calcY = 0;
        for(int i = 0; i < 11 ; i++){
            for(int j = 0; j < 20; j++){
                if(world[i][j] != null){
                    calcX = j + 1;
                    calcY = i + 1;
                    g.drawImage(world[i][j], ( calcX * space), ( calcY * space), this);
                }
            }        
        }
        
        /*
        
        g.setColor(Color.BLACK);
        Player player = new Player();
        g.drawImage(player.getImage(), ovalX, ovalY, this); 
        Wall wall = new Wall();
        g.drawImage(wall.getImage(), 200, 200, this); 
        Crate crate = new Crate();
        g.drawImage(crate.getImage(), 300, 300, this); 
        */
    }
    
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        buildWorld(g);
    }
    
    class TAdapter extends KeyAdapter{
        
        @Override
        public void keyPressed(KeyEvent e) {
        
            int key = e.getKeyCode();
            
/*
            if (key == KeyEvent.VK_LEFT) {
                ovalX -= 1;
            } else if (key == KeyEvent.VK_RIGHT) {
                ovalX += 1;
            } else if (key == KeyEvent.VK_UP) {
                ovalY += 1;
            } else if (key == KeyEvent.VK_DOWN) {
                ovalY -= 1;
            } else if (key == KeyEvent.VK_R) {
                
            }
            * 
            */

            repaint();
    }
    }
}
